package com.suxiaoxiao.springbootlearn.designpattern.adapterpattern.iteratoradapter;

import java.util.Enumeration;
import java.util.Iterator;

/**
 * 迭代器适配器
 * @author 、
 */
public class EnumerationIterator implements Iterator {

    private Enumeration enumeration;

    public EnumerationIterator(Enumeration enumeration) {
        this.enumeration = enumeration;
    }

    @Override
    public boolean hasNext() {
        return enumeration.hasMoreElements();
    }

    @Override
    public Object next() {
        return enumeration.nextElement();
    }

    /**
     * 适配器不支持 remove 方法，所以调用时报错， 在文档中应该写清楚。
     */
    @Override
    public void remove() {
        throw new UnsupportedOperationException();
    }

}
